<template>
    <table border="1" align="center">
      <tr><td><button @click="deleteMany">删除</button></td><td>编号</td><td>姓名</td><td>分数</td><td>生日</td><td>班级</td><td>操作</td></tr>
      <tr v-for="(stu,index) in pageInfo.list" :key="index">
        <td><input type="checkbox" v-model="ids" :value="stu.id" /></td>
        <td>{{stu.id}}</td><td>{{stu.name}}</td><td>{{stu.score}}</td>
        <td>{{stu.birth}}</td><td>{{stu.clazz.name}}</td>
        <td><router-link :to="{path:'/updateStu',query:{stu:stu}}"><button>修改</button></router-link></td></tr>
    </table>
</template>

<script>
    export default {
        name: "StudentTable",
      data(){
          return {
            pageInfo:[],
            ids:[]
          }
      },
      methods:{
          selectByPage(pageNo){
            this.axios({
              url:"/student/selectByPage.do",
              method:"get",
              params:{pageNo:pageNo}
            }).then((resp)=>{
              this.pageInfo=resp.data;
            });
          },
        deleteMany(){
          this.axios({
            url:"/student/delMany.do",
            method:"get",
            params:{ids:this.ids},
            paramsSerializer:function(p){
              // let str="";
              // // p.ids.forEach(function(value,index){
              // //   str+="ids="+value+"&";
              // // });
              // for(let i=0;i<p.ids.length;i++){
              //   str+="ids="+p.ids[i]+"&";
              // }
              // console.log(str);//ids=1&ids=2&ids=3&
              // return str;
              return p.ids.map((value)=>"ids="+value).join("&");
            }
          }).then((resp)=>{
            this.selectByPage(1);
          });
        }
      },
      created() {
          this.selectByPage(1);
      }
    }
</script>

<style scoped>

</style>
